On Compile Time Knuth-Morris-Pratt Precomputation

نویسندگان

  • Derrick G. Kourie
  • Bruce W. Watson
  • Loek G. Cleophas
چکیده

Many keyword pattern matching algorithms use precomputation subroutines to produce lookup tables, which in turn are used to improve performance during the search phase. If the keywords to be matched are known at compile time, the precomputation subroutines can be implemented to be evaluated at compile time versus at run time. This will provide a performance boost to run time operations. We have started an investigation into the use of metaprogramming techniques to implement such compile time evaluation, initially for the Knuth-Morris-Pratt (KMP) algorithm. We present an initial experimental comparison of the performance of the traditional KMP algorithm to that of an optimised version that uses compile time precomputation. During implementation and benchmarking, it was discovered that C++ is not well suited to metaprogramming when dealing with strings, while the related D language is. We therefore ported our implementation to the latter and performed the benchmarking with that version. We discuss the design of the benchmarks, the experience in implementing the benchmarks in C++ and D, and the results of the D benchmarks. The results show that under certain circumstances, the use of compile time precomputation may significantly improve performance of the KMP algorithm.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Efficient validation and construction of Knuth–Morris–Pratt arrays

Knuth-Morris-Pratt (KMP) arrays are known as the ”failure function” of the Knuth-Morris-Pratt string matching algorithm. We present an algorithm to check if an integer array is a KMP array. This gives a method for computing all the distinct KMP arrays.

متن کامل

A Boyer-Moore-style algorithm for regular expression pattern matching

Richard E. Watson Dept. of Mathematics Simon Fraser University Burnaby B.C., Canada watsona@sfu. ca This paper presents a Boyer-Moore type algorithm for regular expression pattern matching, answering an open problem posed by A. V. Aho in 1980 [Aho80, p. 3421. The new algorithm handles patterns specified by regular expressions a generalization of the Boyer-Moore and Commentz-Walter algorithms (w...

متن کامل

6.897: Advanced Data Structures 2 Relevant Concepts

There are two different approaches to solving such problems. Algorithmic approach solves the a new instance of problem every time the algorithm is run. There are a number of well known algorithms that achieve linear time in the size of T such as Karp-Rabin and Knuth-Morris-Pratt. In the data structural approach we can preprocess T , and then we can answer a query involving a pattern P much faster.

متن کامل

Formal Aspects of Polyvariant Specialization

We present the first formal correctness proof of an offline polyvariant specialization algorithm for first-order recursive equations. As a corollary, we show that the specialization algorithm generates a program implementing the search phase of the Knuth-Morris-Pratt algorithm from an inefficient but binding-time-improved string matcher. ∗Basic Research in Computer Science (www.brics.dk), funde...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2011